package net.mujiwulian.utils;

import lombok.extern.slf4j.Slf4j;

import java.util.Random;


/**
 * @Description: 自定义的字符串工具类
 * @Author: fc
 * @Description:
 * @Date:Create：in 2019/10/5 15:44
 */
@Slf4j
public class MyStringUtil {

    public static String CONTENT =
            "<html lang='ch'>"
                    + "<head>"
                    + "    <title>遗忘密码</title>"
                    + "    <meta charset='utf-8'/>"
                    + "</head>"
                    + "<body>"
                    + "<div>"
                    + "时间: "
                    + "-TIME- <br>"
                    + "地址: "
                    + "-IP-"
                    + "<br>"
                    + "    验证码：<span style='color: red'>"
                    + "-CODE-"
                    + "</span><br>"
                    + "    有效期：5分钟！<br>"
                    + "    如非您本人操作请检查账号安全！！！"
                    + "</div>"
                    + "</body>"
                    + "</html>";


    /**
     * @param strings 字符串数组，可变参数
     * @return 只要有一个字符串为空就返回false，全部不为空返回true
     */
    public static boolean isNotBlank(String... strings) {
        if (strings.length == 0) {
            return false;
        }
        for (String str : strings) {
            if (str == null || str.length() == 0) {
                return false;
            }
        }
        return true;
    }

    /**
     * @param strings 字符串数组，可变参数
     * @return 全部都不为空返回false，只要有一个为空就返回true
     */
    public static boolean isBlank(String... strings) {
        return !isNotBlank(strings);
    }

    public static String getRandomString(int length) {
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(62);
            String STR = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            sb.append(STR.charAt(number));
        }
        return sb.toString();
    }
}
